﻿function CloseWindow() {
    window.open('javascript:window.open(\"\", \"_self\", \"\");window.close();', '_self');
}

function addLeadingZero(num) {
    if (num < 10) {
        return "0" + num;
    } else {
        return "" + num;
    }
}

function SetDayList(dayId, monthId, yearId) {
    var month = $("#" + monthId).val();
    var year = $("#" + yearId).val();
    var day = $("#" + dayId).val();

    if ((month != -1) && (year != -1)) {
        var dayInMonth = new Date(year, month, 0).getDate();

        var dayList = $("#" + dayId);
        var firstData = $('#' + dayId + ' option:first-child').val();

        dayList.empty();

        if (firstData == "-1") {
            dayList.append(
                            $('<option/>')
                            .attr('value', "-1")
                            .text("(day)")
                            );
        }
        for (var i = 1; i <= dayInMonth; i++) {
            dayList.append(
                            $('<option/>')
                            .attr('value', String(i))
                            .text(("0" + String(i)).slice(-2))
                            );
            if (day == String(i))
                dayList.val(day);
        }

    }
}

function ClearFileUpload(fuId) {
    var fu = $("#" + fuId);
    var fuName = fu.attr("name");
    fu.replaceWith("<input type='file' style='display:inline;' name='" + fuName + "' id='" + fuId + "' />");
}

function ShowFU(ctrlHide, ctrlShow, ctrlHD) {
    if (confirm('Please confirm if you want to delete videos file')) {
        $("#" + ctrlHide).hide();
        $("#" + ctrlShow).show();
        $("#" + ctrlHD).val('1');
    }
}

function CustomFileUpload_MakeDelete(ctrlFu) {
    if (confirm('Please confirm if you want to delete videos file')) {

        $("#" + ctrlFu + "_lbl").text('');
        $("#" + ctrlFu + "_lbl").hide();
        $("#" + ctrlFu + "_hd1").val('');
        $("#" + ctrlFu + "_lnkDelete").hide();

        ClearFileUpload(ctrlFu + "_fu");
        $("#" + ctrlFu + "_btnFtp").show();
        $("#" + ctrlFu + "_hd").val('1');
    }
}

function CustomFileUpload_MakeClear(ctrlFu) {
    if (confirm('Please confirm if you want to re-choice videos file')) {

        $("#" + ctrlFu + "_lbl").val('');
        $("#" + ctrlFu + "_lbl").hide();
        $("#" + ctrlFu + "_hd1").val('');
        $("#" + ctrlFu + "_lnkClear").hide();

        ClearFileUpload(ctrlFu + "_fu");
        $("#" + ctrlFu + "_btnFtp").show();
        $("#" + ctrlFu + "_hd").val('1');
    }
}

function CustomFileUpload_SelectFile(fileName, ctrlFu) {
    $("#" + ctrlFu + "_lbl").text(fileName);
    $("#" + ctrlFu + "_hd1").val(fileName);
    $("#" + ctrlFu + "_lbl").show();
    $("#" + ctrlFu + "_lnkClear").show();

    ClearFileUpload(ctrlFu + "_fu");
    $("#" + ctrlFu + "_fu").hide();
    $("#" + ctrlFu + "_btnFtp").hide();
}

